package cn.bdqn.util;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

/**
 * Created by Administrator on 2018/8/20.
 */
public class TestEmail {
    public static void main(String[] args) throws MessagingException {
        //创建邮件
//        mail.store.protocol,
//        *                  mail.transport.protocol, mail.host, mail.user,
//        *                  and mail.from
        Properties prop = new Properties();
        prop.setProperty("mail.from","1160771832@qq.com");
        prop.setProperty("mail.user","1160771832@qq.com");
        prop.setProperty("mail.host","smtp.qq.com");
        prop.setProperty("mail.transport.protocol","smtp");
        Session session = Session.getInstance(prop);
        session.setDebug(true);
        MimeMessage email = new MimeMessage(session);
        email.setSubject("这是邮件主题");
        email.setText("这是邮件的正文.您的激活码为XXXX");
        email.setRecipient(Message.RecipientType.TO, new InternetAddress("872915420@qq.com"));
        //发送邮件
        Transport ts = session.getTransport();
        ts.connect("1160771832@qq.com","unoqwwgvnquwijeg");
        ts.sendMessage(email,email.getAllRecipients());
        ts.close();
    }
}
